clear all
clc
close all
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%plot consumption of young and old by income
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure;

%Income ≤ 20,261
%cd 2a_baseline_w_12481;
load all_results


conflevel=0.95;
factor=-norminv((1-conflevel)/2);
weekstr=[];
for ww=1:1:numel(Ivec)
    weekstr=[weekstr {['Week ',num2str(ww)]}];
end

%data income bracket 1, i.e. <20k
data_bracket_1=[-0.089031060	0.007826505
-0.098171132	0.006485070
-0.253920427	0.008250186
-0.330947289	0.007229570
-0.153218248	0.008286776
-0.194603667	0.006907720
0.012341942	0.008268015
-0.048548298	0.007162457
0.073558679	0.009461842
0.005467759	0.007799981
0.029878200	0.008579561
-0.012034959	0.007285388
0.027185299	0.008765036
-0.011456029	0.007412558
-0.072863989	0.008912305
-0.112296404	0.007697069
-0.025825496	0.008958436
-0.083364650	0.007674255
-0.104367499	0.009410930
-0.153431873	0.008065505
-0.268464628	0.010106764
-0.340324113	0.008648499
-0.152123346	0.009773952
-0.194279327	0.008502136
-0.023338001	0.010275304
-0.049907683	0.008835571
-0.034103382	0.010433679
-0.051707253	0.008918299];

Consy_data=100*data_bracket_1(1:2:end-1,1);
Conso_data=100*data_bracket_1(2:2:end,1);
par.dat_stderr_young=data_bracket_1(1:2:end-1,2);
par.dat_stderr_old=data_bracket_1(2:2:end,2);

sub1=subplot(2,2,1);
plot((1:1:14),Consy_data,'b--','LineWidth',2); hold on %data mean young
grpyat = [ (1:1:14)' (Consy_data(1:end)-factor*100*par.dat_stderr_young(1:end)'); (14:-1:1)' (Consy_data(end:-1:1))+factor*100*par.dat_stderr_young(end:-1:1)'];
patch(grpyat(:,1),grpyat(:,2),[0.8 0.8 1],'edgecolor',[0.8 0.8 1]); hold on %data 95% young
plot((1:1:14),cons_monthly.Cy.Consy(1:end-1),'b-','LineWidth',2); hold on %model young
plot((1:1:14),Conso_data,'r--','LineWidth',2);%data mean old
grpyat = [ (1:1:14)' (Conso_data(1:end)-factor*100*par.dat_stderr_old(1:end)'); (14:-1:1)' (Conso_data(end:-1:1))+factor*100*par.dat_stderr_old(end:-1:1)'];
patch(grpyat(:,1),grpyat(:,2),[1 0.8 0.8],'edgecolor',[1 0.8 0.8]); hold on%data 95% old
plot((1:1:14),cons_monthly.Co.Conso(1:end-1),'r-','LineWidth',2); hold on%model old
plot((1:1:14),Consy_data,'b--','LineWidth',2); hold on %data mean young
plot((1:1:14),cons_monthly.Cy.Consy(1:end-1),'b-','LineWidth',2); hold on %model young
plot((1:1:14),Conso_data,'r--','LineWidth',2);%data mean old
plot((1:1:14),0*Conso_data,'k:','LineWidth',1.5);
ylabel('% Dev. from no-epi baseline','FontSize',12);

sub1.XLim(1)=1;%'01-Mar-2020';
sub1.XLim(2)=14;%'01-Mar-2021';
sub1.YLim(1)=-60;
sub1.YLim(2)=15;


datstring=['Mar 2020'
    'Apr 2020'
    'May 2020'
    'Jun 2020'
    'Jul 2020'
    'Aug 2020'
    'Sep 2020'
    'Oct 2020'
    'Nov 2020'
    'Dec 2020'
    'Jan 2021'
    'Feb 2021'
    'Mar 2021'
    'Apr 2021'];

xticks(1:14);
xticklabels(datstring)
xtickangle(-35);
set(gca,'FontSize',12);

title('Income ≤ 20,261')
grid on;
box off


cd .. 
 

cd 2b_baseline_w_28566;
load all_results



%data income bracket 2, i.e.between 20 and 40k
data_bracket_2=[-0.14732845	0.006056653
-0.15720618	0.007000236
-0.35474248	0.006845531
-0.49183509	0.008434610
-0.23922705	0.006565755
-0.28849877	0.007713677
-0.01896897	0.006641774
-0.08820133	0.007678264
0.03928627	0.007472305
-0.04699534	0.008464927
0.05768794	0.006745503
-0.05808254	0.007890708
0.02481120	0.006690182
-0.03940244	0.007787456
-0.08240864	0.006919841
-0.11277394	0.008121728
-0.07350497	0.006963813
-0.11967747	0.008195005
-0.14379604	0.007100190
-0.19865902	0.008455248
-0.30180575	0.007255682
-0.37891278	0.009301103
-0.23968085	0.007458358
-0.29524442	0.009247631
-0.10937018	0.007751389
-0.12406671	0.009505900
-0.09165940	0.007711470
-0.10317951	0.009620296];

Consy_data=100*data_bracket_2(1:2:end-1,1);
Conso_data=100*data_bracket_2(2:2:end,1);
par.dat_stderr_young=data_bracket_2(1:2:end-1,2);
par.dat_stderr_old=data_bracket_2(2:2:end,2);



sub1=subplot(2,2,2);
plot((1:1:14),Consy_data,'b--','LineWidth',2); hold on %data mean young
grpyat = [ (1:1:14)' (Consy_data(1:end)-factor*100*par.dat_stderr_young(1:end)'); (14:-1:1)' (Consy_data(end:-1:1))+factor*100*par.dat_stderr_young(end:-1:1)'];
patch(grpyat(:,1),grpyat(:,2),[0.8 0.8 1],'edgecolor',[0.8 0.8 1]); hold on %data 95% young
plot((1:1:14),cons_monthly.Cy.Consy(1:end-1),'b-','LineWidth',2); hold on %model young
plot((1:1:14),Conso_data,'r--','LineWidth',2);%data mean old
grpyat = [ (1:1:14)' (Conso_data(1:end)-factor*100*par.dat_stderr_old(1:end)'); (14:-1:1)' (Conso_data(end:-1:1))+factor*100*par.dat_stderr_old(end:-1:1)'];
patch(grpyat(:,1),grpyat(:,2),[1 0.8 0.8],'edgecolor',[1 0.8 0.8]); hold on%data 95% old
plot((1:1:14),cons_monthly.Co.Conso(1:end-1),'r-','LineWidth',2); hold on%model old
plot((1:1:14),Consy_data,'b--','LineWidth',2); hold on %data mean young
plot((1:1:14),cons_monthly.Cy.Consy(1:end-1),'b-','LineWidth',2); hold on %model young
plot((1:1:14),Conso_data,'r--','LineWidth',2);%data mean old
plot((1:1:14),0*Conso_data,'k:','LineWidth',1.5);
title('20,261 < Income ≤ 40,522')
grid on;
ylabel('% Dev. from no-epi baseline','FontSize',12);


sub1.XLim(1)=1;%'01-Mar-2020';
sub1.XLim(2)=14;%'01-Mar-2021';
sub1.YLim(1)=-60;
sub1.YLim(2)=15;


datstring=['Mar 2020'
    'Apr 2020'
    'May 2020'
    'Jun 2020'
    'Jul 2020'
    'Aug 2020'
    'Sep 2020'
    'Oct 2020'
    'Nov 2020'
    'Dec 2020'
    'Jan 2021'
    'Feb 2021'
    'Mar 2021'
    'Apr 2021'];

xticks(1:14);
xticklabels(datstring)
xtickangle(-35);
set(gca,'FontSize',12);
box off

cd .. 

cd 2c_baseline_w_59490;
load all_results


cd ..
cd 2a_baseline_w_12481



%data income bracket 3, i.e.>40k
data_bracket_3=[-0.171103805	0.01491964
-0.203559005	0.01115019
-0.426892194	0.01690553
-0.527164287	0.01240102
-0.289137700	0.01644794
-0.362563686	0.01220052
-0.068702658	0.01608600
-0.125351486	0.01217436
-0.048266327	0.01716045
-0.077150041	0.01271899
0.027268968	0.01747190
-0.082755345	0.01252547
-0.004144011	0.01708042
-0.073339374	0.01221493
-0.128942075	0.01682431
-0.159072633	0.01235186
-0.122449275	0.01756266
-0.161761440	0.01280182
-0.140653917	0.01759045
-0.240420184	0.01286102
-0.374773722	0.01877633
-0.404296474	0.01330781
-0.298717026	0.01945394
-0.349391408	0.01368463
-0.198083161	0.01976362
-0.190337369	0.01424520
-0.129866045	0.02028983
-0.145680953	0.01466317];

Consy_data=100*data_bracket_3(1:2:end-1,1);
Conso_data=100*data_bracket_3(2:2:end,1);
par.dat_stderr_young=data_bracket_3(1:2:end-1,2);
par.dat_stderr_old=data_bracket_3(2:2:end,2);


sub1=subplot(2,2,3);
plot((1:1:14),Consy_data,'b--','LineWidth',2); hold on %data mean young
grpyat = [ (1:1:14)' (Consy_data(1:end)-factor*100*par.dat_stderr_young(1:end)'); (14:-1:1)' (Consy_data(end:-1:1))+factor*100*par.dat_stderr_young(end:-1:1)'];
patch(grpyat(:,1),grpyat(:,2),[0.8 0.8 1],'edgecolor',[0.8 0.8 1]); hold on %data 95% young
plot((1:1:14),cons_monthly.Cy.Consy(1:end-1),'b-','LineWidth',2); hold on %model young
plot((1:1:14),Conso_data,'r--','LineWidth',2);%data mean old
grpyat = [ (1:1:14)' (Conso_data(1:end)-factor*100*par.dat_stderr_old(1:end)'); (14:-1:1)' (Conso_data(end:-1:1))+factor*100*par.dat_stderr_old(end:-1:1)'];
patch(grpyat(:,1),grpyat(:,2),[1 0.8 0.8],'edgecolor',[1 0.8 0.8]); hold on%data 95% old
plot((1:1:14),cons_monthly.Co.Conso(1:end-1),'r-','LineWidth',2); hold on%model old
plot((1:1:14),Consy_data,'b--','LineWidth',2); hold on %data mean young
plot((1:1:14),cons_monthly.Cy.Consy(1:end-1),'b-','LineWidth',2); hold on %model young
plot((1:1:14),Conso_data,'r--','LineWidth',2);%data mean old
plot((1:1:14),0*Conso_data,'k:','LineWidth',1.5);
title('Income >40,522')
grid on;
box off


sub1.XLim(1)=1;%'01-Mar-2020';
sub1.XLim(2)=14;%'01-Mar-2021';
sub1.YLim(1)=-60;
sub1.YLim(2)=15;


datstring=['Mar 2020'
    'Apr 2020'
    'May 2020'
    'Jun 2020'
    'Jul 2020'
    'Aug 2020'
    'Sep 2020'
    'Oct 2020'
    'Nov 2020'
    'Dec 2020'
    'Jan 2021'
    'Feb 2021'
    'Mar 2021'
    'Apr 2021'];

xticks(1:14);
xticklabels(datstring)
xtickangle(-35);
set(gca,'FontSize',12);






legend1=legend('Data: Young (Mean)','Data: Young (95%)', 'Model: Young', 'Data: Old (Mean)','Data: Old (95%)', 'Model: Old','Location','Southwest','FontSize',12);
box off;
legend box off;
ylabel('% Dev. from no-epi baseline','FontSize',12);
set(legend1,...
   'Position',[0.633389773195232 0.190090275563771 0.226852274456108 0.189155971667017],...
    'Orientation','vertical');




suptitle('Consumption of Young and Old by Income Groups');

orient landscape
print -dpdf -fillpage model_data_income_brackets

 